<!--系统参数-->
<template>
  <div class="system-parameter">
    <a-card size="small" :headStyle="{ background: '#f9f9f9' }" :bodyStyle="{ height: 'calc(100% - 48px)' }">
      <div slot="title">
        <div class="top-icon">
          <icon-font type="icon-xitongcanshu" />
        </div>
        <span>系统参数</span>
      </div>
      <div slot="extra">
        <a-button type="primary" icon="plus" @click="systemClick('add')">新增参数</a-button>
      </div>
      <el-table
        :data="systemTableData"
        highlight-current-row
        border
        height="100%"
        :row-style="{height:'40px'}"
        :cell-style="{padding:'0px'}"
        :header-cell-style="{background: '#FAFAFA', padding: 0, height: '40px', color: '#666666'}"
        style="width: 100%">
        <slot v-for="(item,index) in systemColumns">
          <el-table-column
            :key="index"
            :property="item.field"
            :label="item.title"
            :width="item.width"
            show-overflow-tooltip
            sortable>
          </el-table-column>
        </slot>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <a @click="systemClick('edit', scope.row)">编辑</a>
            <a-divider type="vertical" />
            <a @click="systemClick('del', scope.row)">删除</a>
          </template>
        </el-table-column>
      </el-table>
    </a-card>

    <!-- 系统参数弹出框 -->
    <a-modal
      :maskClosable="false"
      :title="modalTitle"
      v-model="dialogFormVisible"
      @ok="handleOk">
      <a-form
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 18 }"
        :form="form">
        <a-form-item label="键" >
          <a-input v-decorator="[ 'Sys_Key', {rules: [{ required: true, message: '请输入键!' }]} ]" />
        </a-form-item>
        <a-form-item label="值">
          <a-input type="textarea" v-decorator="['Sys_Value', {rules: [{ required: true, message: '请输入值!' }]} ]" />
        </a-form-item>
        <a-form-item label="备注">
          <a-input type="textarea" v-decorator="[ 'Sys_Remark' ]" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
import pick from 'lodash.pick'
export default {
  name: 'SystemParameter',
  components: {
  },
  data () {
    return {
      systemTableData: [], // 系统参数表格数据
      systemColumns: [ // 系统参数表头数据
        {
          title: '键',
          field: 'Sys_Key'
        },
        {
          title: '值',
          field: 'Sys_Value'
        },
        {
          title: '备注',
          field: 'Sys_Remark'
        }
      ],
      dialogFormVisible: false, // 系统参数弹出框是否显示
      modalTitle: '', // 系统参数弹出框标题
      form: this.$form.createForm(this)
    }
  },
  created () {
    this.getTableData()
  },
  mounted () {
  },
  methods: {
    // 获取系统参数表格数据
    getTableData () {
      this.$vueAjax.get('Sys_Base_SysConfig/get', {}).then(res => {
        this.systemTableData = res.List
      })
    },
    // 系统参数增删改事件
    systemClick (val, row) {
      switch (val) {
        case 'add':
          this.modalTitle = '参数新增'
          this.dialogFormVisible = true
          this.form.resetFields() // 表单清空
          break
        case 'edit':
          this.modalTitle = '参数编辑'
          this.dialogFormVisible = true
          this.$nextTick(() => { // 表单赋值
            this.form.setFieldsValue(pick(row, ['Sys_Key', 'Sys_Value', 'Sys_Remark']))
          })
          break
        case 'del':
          var this_ = this
          this.$confirm({
            title: '提示',
            content: '此操作将永久删除该文件, 是否继续?',
            okText: '确认',
            cancelText: '取消',
            onOk () {
              this_.$message.success('删除成功')
            }
          })
          break
        default:
          break
      }
    },
    handleOk () {}
  }
}
</script>
<style lang="less" scoped>
.system-parameter {
  width: 100%;
  height: 100%;
  padding: 10px 10px 0;
  background: #f0f2f5;
}
</style>
